package com.example.android.common.adapters;

import java.util.List;

import com.example.android.common.models.Article;
import com.example.android.slidingtabscolors.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ArticleAdapter extends ArrayAdapter<Article>{

	private int resourceId;
	int num = 1;
	
	public ArticleAdapter(Context context, int resource, List<Article> objects) {
		super(context, resource, objects);
		this.resourceId = resource;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		Article article = getItem(position);
		View row = convertView;
		if(row == null) {
			LayoutInflater flater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = flater.inflate(this.resourceId, null);
		}
		
		TextView tvArticleTitleView = (TextView) row.findViewById(R.id.tvArticleTitle);
		TextView tvNewspaperName = (TextView) row.findViewById(R.id.tvNewspaperName);
		TextView tvNumberOfComment = (TextView) row.findViewById(R.id.tvNumberOfComment);
		
		tvArticleTitleView.setText(article.getArticleTitle());
		tvNewspaperName.setText(article.getNewspaperName());
		tvNumberOfComment.setText(article.getNumberOfComment());
		
		if(position % 2 == 1) {
			row.setBackgroundColor(Color.DKGRAY);
		} else {
			row.setBackgroundColor(Color.WHITE);
		}
		
		return row;
	}

}
